#!/usr/bin/env python
import os
import sys

# 导入兼容性补丁以解决Python 3.3+中的collections问题
try:
    import compatibility_patch
except ImportError:
    pass

# 添加项目相关目录到Python路径
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
THIRD_PARTY_ROOT = os.path.join(PROJECT_ROOT, "thirdparty")
THEME_ROOT = os.path.join(PROJECT_ROOT, "theme")

# 重要：将thirdparty目录添加到Python路径的最前面
sys.path.insert(0, THIRD_PARTY_ROOT)
sys.path.insert(0, THEME_ROOT)
sys.path.insert(0, os.path.join(PROJECT_ROOT, "apps"))

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
    
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    
    execute_from_command_line(sys.argv)
